<template>
  <div class="container tree-list-layout">
    <treeWarehouse @click="handleTreeNodeClick" ref="treeWarehouse" class="box-left" />
     <!-- 库存列表 -->
     <data-view
      class="box-right"
      ref="dataView"
      propViewKey="wm_stock_safety"
      propViewForm="wm/stock-safety/detail.vue"
      :propInitData="selectedTreeNode"
      @before-button-click="beforeButtonClick"
      :propIsTdesign="true"
    />
  </div>
</template>

<script>
import treeWarehouse from '@/components/custom/bus/treeWarehouse.vue'

export default {
  name: 'stocksafety',
  data() {
    return {
      selectedTreeNode: {
        id: 0
      },
    }
  },
  created() {
  },
  components: {
    treeWarehouse,
  },
  watch: {
  },
  methods: {
    // 树点击后
    handleTreeNodeClick(data) {
      this.selectedTreeNode = data
      let queryWrapper = data.id == 0 ? this.$newWrapper() : this.$newWrapper().eq('warehouseId', data.id)
      this.$refs.dataView.setQueryWrapper(queryWrapper)
    },

    //按钮操作前
    beforeButtonClick({ btn, call }) {
      if (btn.code == 'vb-add') { //添加前
        if (!this.selectedTreeNode || this.selectedTreeNode.id == 0) {
          this.utilMessage.warning('左侧仓库树请选择非跟节点进行添加操作')
          call(false)
        }
      }
    },
  }
}
</script>
